<template>
  <div class="pc-home" v-if="!isphone">
    <div class="bannerbox">
      <div class="block">
        <el-carousel trigger="click" height="700px">
          <el-carousel-item v-for="item in banner" :key="item.id">
            <img :src="item.bigimg" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
    <!-- <div class="samllbar"></div> -->
    <section class="shipping_area mb-70">
      <div class="container">
        <div class="row">
          <div class="col-lg-3 col-md-6">
            <div class="single_shipping">
              <div class="shipping_icone">
                <img src="@/assets/homeimg/shipping1.png" alt="" />
              </div>
              <div class="shipping_content">
                <h2>全场国包邮</h2>
                <p>Free shipping on all order</p>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6">
            <div class="single_shipping">
              <div class="shipping_icone">
                <img src="@/assets/homeimg/shipping2.png" alt="" />
              </div>
              <div class="shipping_content">
                <h2>24/7 全天候在线</h2>
                <p>Contact us 24 hours a day</p>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6">
            <div class="single_shipping">
              <div class="shipping_icone">
                <img src="@/assets/homeimg/shipping3.png" alt="" />
              </div>
              <div class="shipping_content">
                <h2>30天无条件退货</h2>
                <p>You have 30 days to Return</p>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6">
            <div class="single_shipping">
              <div class="shipping_icone">
                <img src="@/assets/homeimg/shipping4.png" alt="" />
              </div>
              <div class="shipping_content">
                <h2>安心支付,省心</h2>
                <p>We ensure secure payment</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <div class="hotthree">
      <div class="hotshow">
        <div class="left">
          <img
            src="https://wwwstatic.vivo.com.cn/vivoportal/files/image/home/20220507/6107a2f64b5c2f35e51f5220f76e201a.jpg"
            alt=""
          />
        </div>
        <div class="center">
          <img
            src="https://dsfs.oppo.com/archives/202206/2022062202060862b2b2b803c95.jpg?_w_=2624&_h_=960"
            alt=""
          />
        </div>
        <div class="right">
          <img
            src="https://fms.res.meizu.com/dms/2022/02/25/4197cdad-be8f-456d-b61d-7d06256cbf20.jpg"
            alt=""
          />
        </div>
      </div>
    </div>

    <div class="hotsalewrap">
      <div class="hotsale">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <h1>热卖产品</h1>
          </div>
          <div
            class="goodsitem"
            v-for="item in hotsale.slice(0, 8)"
            :key="item"
          >
            <img v-lazy="item.img" alt="" />
            <h2>售价:￥{{ item.price }}</h2>
            <!-- <h3>
              {{
                item.gid == '1' ? item.brand + item.name : item.name.slice(0, 8)
              }}
            </h3> -->
            <p>{{ item.desc }}</p>
          </div>
        </el-card>
      </div>
    </div>
  </div>
  <div class="phone-home" v-else>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in banner" :key="item.id"
        ><img :src="item.smlimg" alt=""
      /></van-swipe-item>
    </van-swipe>
    <ul class="menubar">
      <li @click="goGoodslist(0)">
        <i><img src="@/assets/homeimg/shouji.png" alt="" /></i>
        <span>手机</span>
      </li>
      <li @click="goGoodslist(1)">
        <i><img src="@/assets/homeimg/pc.png" alt="" /></i>
        <span>PC</span>
      </li>
      <li @click="goGoodslist(2)">
        <i><img src="@/assets/homeimg/music.png" alt="" /></i>
        <span>配件</span>
      </li>
      <li @click="goGoodslist(3)">
        <i><img src="@/assets/homeimg/youxi.png" alt="" /></i>
        <span>掌机</span>
      </li>
    </ul>
    <div class="pdtlist">
      <div
        class="pdtitem"
        v-for="item in hotsale.slice(0, 8)"
        :key="item.id"
        @click="goDetail(item.id)"
      >
        <div class="imgbox" style="min-height: 150px">
          <img v-lazy="item.img" alt="" />
        </div>
        <span class="title">{{
          item.gid == '1' ? item.brand + item.name : item.name.slice(0, 8)
        }}</span>
        <span class="price">售价:￥{{ item.price }}</span>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import { getbanner, getHotSale } from '@/api/index';
export default {
  data() {
    return {
      banner: [],
      catelist: [],
      hotsale: [],
    };
  },
  computed: {
    // 取出media中的isphone 其他页面按此方法取值
    // isphone为true时，手机端模板，否则网页端模板
    ...mapState('media', ['isphone']),
  },
  created() {
    getbanner().then((res) => {
      this.banner = res.data.data;
      console.log(this.banner);
    });
    getHotSale().then((res) => {
      this.hotsale = res.data.data;
      console.log(this.hotsale);
    });
  },
  methods: {
    goGoodslist(id) {
      this.$router.push('/mobilelist/' + id);
    },
    goDetail(id) {
      this.$router.push('/detail/' + id);
    },
  },
};
</script>
<style lang="scss" scoped>
.pc-home {
  * {
    background-repeat: no-repeat;
  }
  .headwrap {
    background-color: #f8f9f9;
    width: 100%;
    height: 44px;
    border: 1px solid #ebebeb;
    .head {
      width: 1200px;
      height: 100%;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .techinfo {
        color: #242424;
        line-height: 44px;
        font-size: 14px;
      }
      .login_reg {
        font-size: 14px;
        color: #242424;
        span {
          cursor: pointer;
        }
      }
    }
  }
  .topwrap {
    height: 100px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    .top {
      width: 1200px;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .logo {
        img {
          height: 33px;
        }
      }
      .searchbox {
        vertical-align: middle;
        width: 600px;
        border: 1px solid #ebebeb;
        display: flex;
        align-items: center;
        button {
          background-color: #0063d1;
          color: white;
        }
        .el-select {
          width: 100px;
        }
        .el-input {
        }
      }
      .cartbox {
        width: 80px;
        display: flex;
        justify-content: space-between;
        font-size: 25px;
        i {
          font-weight: bold;
          font-size: 16px;
          color: #0063d1;
        }
      }
    }
  }
  // .bannerbox {
  //   height: 1000px;
  // }
  .menuwrap {
    width: 100%;
    height: 56px;
    background-color: #0063d1;
    .menu {
      width: 1200px;
      margin: 0 auto;
      display: flex;
      .el-dropdown {
        color: white;
        font-weight: bold;
        width: 200px;
        height: 56px;
        background-color: #1953b4;
        line-height: 56px;
        text-align: center;
        vertical-align: middle;
        i {
          font-weight: normal;
        }
      }
      .menulist {
        display: flex;
        font-size: 16px;
        .el-dropdown {
          background-color: transparent;
        }
      }
    }
  }
  .bannerbox img {
    width: 100%;
  }
  .samllbar {
    width: 100%;
    height: 200px;
    background: url('@/assets/homeimg/littlebar.png');
    background-size: 100%;
  }
  .hotthree {
    width: 100%;
    height: 300px;
    .hotshow {
      width: 1200px;
      height: 300px;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      .left,
      .right {
        width: 270px;
        height: 270px;
        background-color: red;
        img {
          width: 100%;
          height: 270px;
        }
      }

      .center {
        width: 570px;
        height: 270px;
        background-color: #0063d1;
        img {
          width: 100%;
          height: 270px;
        }
      }
    }
  }
  .hotsalewrap {
    width: 100%;
    // background-color: #0063d1;
    .hotsale {
      width: 1200px;
      margin: 0 auto;
      .hotsale {
        h1 {
          color: black;
          line-height: 70px;
        }
      }
    }
  }
  .goodsitem {
    background-color: white;
    border: 1px solid #f8f8f8;
    img {
      width: 100%;
    }
  }
  .el-card__body .goodsitem {
    margin: 10px 20px;
    width: 220px;
    height: 320px;
    background-color: white;
  }
  .container {
    width: 1200px;
    height: 100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
  }
  .row {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .shipping_area {
      margin-bottom: 43px;
    }
  }
  @media only screen and (max-width: 767px) {
    .shipping_area {
      margin-bottom: 28px;
    }
  }

  .single_shipping {
    display: flex;
  }
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .single_shipping {
      margin-bottom: 25px;
    }
  }
  @media only screen and (max-width: 767px) {
    .single_shipping {
      margin-bottom: 28px;
    }
  }

  .shipping_icone {
    margin-right: 20px;
  }
  @media only screen and (min-width: 992px) and (max-width: 1199px) {
    .shipping_icone {
      margin-right: 12px;
    }
  }

  .shipping_content h2 {
    font-size: 14px;
    line-height: 20px;
    text-transform: capitalize;
    font-weight: 700;
    margin-bottom: 4px;
  }
  .shipping_content p {
    font-size: 13px;
    line-height: 18px;
  }

  /*home two css here*/
  .shipping_two {
    margin-bottom: 48px;
  }
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .shipping_two {
      margin-bottom: 20px;
    }
  }
  @media only screen and (max-width: 767px) {
    .shipping_two {
      margin-bottom: 20px;
    }
  }

  /*home four css here*/
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .shipping_four {
      margin-bottom: 70px;
    }
  }
  @media only screen and (max-width: 767px) {
    .shipping_four {
      margin-bottom: 60px;
    }
  }

  .shipping_inner {
    border: 1px solid #ebebeb;
  }
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .shipping_inner {
      padding: 11px 0 15px;
    }
  }
  @media only screen and (max-width: 767px) {
    .shipping_inner {
      padding: 11px 0 15px;
    }
  }
  .shipping_inner .single_shipping {
    padding: 25px 25px 20px 25px;
    border-right: 1px solid #ebebeb;
  }
  @media only screen and (min-width: 992px) and (max-width: 1199px) {
    .shipping_inner .single_shipping {
      padding: 22px 5px 19px 8px;
    }
  }
  @media only screen and (min-width: 768px) and (max-width: 991px) {
    .shipping_inner .single_shipping {
      border-right: 0;
      margin-bottom: 0;
      padding: 18px 25px 13px 25px;
    }
  }
  @media only screen and (max-width: 767px) {
    .shipping_inner .single_shipping {
      border-right: 0;
      margin-bottom: 0;
      padding: 18px 25px 13px 25px;
    }
  }
  .shipping_inner .single_shipping.last_child {
    border: 0;
  }
  @media only screen and (min-width: 992px) and (max-width: 1199px) {
    .shipping_inner .shipping_icone {
      margin-right: 12px;
    }
  }
}
.phone-home {
  .van-swipe-item {
    img {
      width: 100%;
    }
  }
  .van-grid {
    margin-bottom: 15px;
  }
  .pdtlist {
    width: 90%;
    min-height: 500px;
    margin: 0 auto 50px;
    border-radius: 10px;
    background-color: #f8f8f8;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .pdtitem {
      border-radius: 10px;
      width: 45%;
      height: 220px;
      background-color: white;
      margin-top: 5px;
      display: flex;
      flex-direction: column;
      img {
        width: 100%;
      }
      .title {
        font-weight: bolder;
        font-size: 14px;
      }
      .desc {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .price {
        color: red;
      }
    }
  }
  .menubar {
    text-align: center;
    width: 90%;
    height: 60px;
    border-radius: 10px;
    background-color: #f8f8f8;
    margin: 10px auto;
    display: flex;
    justify-content: space-around;
    li {
      width: 20%;
      border-radius: 10px;
      display: flex;
      flex-direction: column;
      i {
        img {
          width: 40px;
        }
      }
      span {
        font-weight: bold;
        font-size: 12px;
        color: #dc6a06;
      }
    }
  }
}
</style>
